package tp.pr5.console;

import tp.pr5.Directions;
import tp.pr5.GameObserver;
import tp.pr5.MapObserver;
import tp.pr5.MensajesConst;
import tp.pr5.PlayerObserver;
import tp.pr5.RoomInfo;
import tp.pr5.items.ItemList;

public class Console implements GameObserver, MapObserver, PlayerObserver {
	
	public Console()
	{
		
	}

	@Override
	public void gameError(String msg) {
		System.out.print(msg);
		
	}

	@Override
	public void gameHelp() {
		System.out.println(MensajesConst.help);
		
	}

	@Override
	public void gameOver(boolean win) {
		if (!win) {		
			System.out.println(MensajesConst.muerto);
		}
		if (win){
			System.out.println(MensajesConst.salidamsg);

		}
		this.gameQuit();
	}

	@Override
	public void gameQuit() {
		
		System.exit(0);
		
	}

	
	@Override
	public void gameStart(RoomInfo initialRoom, int playerPoints,
			int playerHealth) {
		this.showStatus(initialRoom, playerHealth,playerPoints);
		
	}

	@Override
	public void playerHasExaminedRoom(RoomInfo r) {
		System.out.println(r.getDescription());
		
	}

	@Override
	public void roomEntered(Directions direction, RoomInfo targetRoom) {
		System.out.println("...moving to " + direction);

	}

	@Override
	public void inventoryUpdate(ItemList inventory) {
	//	System.out.println("> ");
		
	}

	@Override
	public void itemEmpty(String itemName) {
		System.out.println("The "+itemName+" is empty. It is deleted from the inventory.");
		
	}

	@Override
	public void itemLooked(String description) {
		System.out.println(description);		
	}

	@Override
	public void itemUsed(String itemName) {
		System.out.println("Something changes ...");
		
	}

	@Override
	public void playerDead() {
		System.out.println(MensajesConst.muerto);
		
	}

	@Override
	public void playerLookedInventory(ItemList inventory) {
		String lista=inventory.toString();
		String mensaje=MensajesConst.playerItems+lista;
				
		if (lista==null)
		{ 
			mensaje=MensajesConst.playerNoItems;
		}
		System.out.println(mensaje);
		
	}

	@Override
	public void playerUpdate(int newHealth, int newScore) {
		System.out.println("HEALTH = " + String.valueOf(newHealth)
				+ ", SCORE =" + String.valueOf(newScore));
		
	}
	private void showStatus(RoomInfo habitacionActual,int health,int points)
	{

		System.out.println(habitacionActual.getDescription()
				+ "\nHEALTH = " + String.valueOf(health)
				+ ", SCORE =" + String.valueOf(points));
	}
}
